﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Views
{
    /// <summary>
    /// The class manages and provides access to the view factory
    /// </summary>
    public class ViewManager
    {
        /// <summary>
        /// Instance of the view factory that we are using
        /// </summary>
        public static IViewFactory ViewFactory
        {
            get;
            private set;
        }

        /// <summary>
        /// If the ViewFactory has not already been initialised then start it
        /// </summary>
        /// <param name="viewFactory">The instance of the ViewFactory to use</param>
        /// <returns>True if the ViewFactory was linied to this manager correctly, otherwise false</returns>
        /// <remarks>Once start factory has succeeded once then the factory must be stopped before another one can be started</remarks>
        public static bool StartFactory(IViewFactory viewFactory)
        {
            bool result = false;

            if (ViewFactory == null)
            {
                ViewFactory = viewFactory;
                result = true;
            }

            return result;
        }

        /// <summary>
        /// Stop and remove the current ViewFactory from this manager
        /// </summary>
        public static void StopFactory()
        {
            ViewFactory = null;
        }
    }
}
